<?php $__env->startSection('css'); ?>
    <style>
        .layer-go-back{
            display:none;
        }
    </style>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('title'); ?>
    <li class="cur">
        <span>会员资料设置</span>
    </li>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>

    <div class="alert alert-success" role="alert" style="margin-top:10px;width: 70%;margin-left: 15px;">
        选中一行并拖动鼠标，进行排列 <strong>字段名称</strong> 组合顺序
    </div>

    <input type="hidden" name="function_id" id="function_id" value="<?php echo e(isset($function_id) ? $function_id : ''); ?>">

    <div class="comm_content" style="margin-left: 15px;margin-top:20px;width: 70%;">
        <div class="panel panel-default">
            <div class="panel-heading">会员资料设置列表</div>
            <table class="table table-bordered table-hover">
                <thead>
                <tr>
                    <th style="text-align:center;">字段名称</th>
                    <th style="text-align:center;">是否显示</th>
                    <th style="text-align:center;">是否必填</th>
                    <th style="text-align:center;">其他</th>
                </tr>
                </thead>
                <tbody id="sortable_tr">
                </tbody>
            </table>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"></label>
        <div class="col-sm-9">
            <input type="button"  value="保存" onclick="func.edit();" class="btn btn-success" >
        </div>
    </div>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('js'); ?>
    <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
    <script type="text/javascript">

        $(function(){
            var configure_array = 0 ;
            if ( !E.isEmpty(<?php echo isset($configure_json) ? $configure_json : 0; ?>) ) {
                configure_array = eval( '(' + '<?php echo isset($configure_json) ? $configure_json : 0; ?>'  + ')' );
            }

//            if ( configure_array ) {

                //列参数
                var column_data = {
                    'birthday' : '生日日期' ,
                    'mobile' : '手机号码' ,
                    'QQ' : 'QQ号' ,
                    'custname' : '姓名' ,
                    'email' : '电子邮件' ,
                    'maritalStatus' : '婚姻状态' ,
                    'marryDay' : '结婚纪念日' ,
                    'nickName' : '昵称' ,
                    'identityCard' : '身份证号' ,
                    'phone' : '电话号码' ,
                    'sexy' : '性别' ,
                    'pcc' : '省市区（县）',
                    'address' : '详细地址' ,
                    'referee' : '推荐人'
                } ;

                var html = '' ;

                //已存在配置
                if( !E.isEmpty( configure_array.configure ) ) {

                    $.each( configure_array.configure , function( k ,v ) {

                        if( E.isEmpty( column_data[k] ) ) {
                            return true ;
                        }

                        html +='<tr class="column layui-form" name="'+ k +'" >';
                        html +='<td style="text-align:center;">'+ column_data[k] +'</td>';


                        if( k == 'mobile') {
                            html +='<td style="text-align:center;"><input type="checkbox" class="is_show" checked disabled lay-skin="primary"></td>';
                            html +='<td style="text-align:center;"><input type="checkbox" class="is_must" checked disabled lay-skin="primary"></td>';

                            html += '<td>';
                            if( v.is_proving == 1 ) {
                            html += '<input type="checkbox" class="is_proving" checked lay-skin="primary">  是否开启短信验证&nbsp;&nbsp;&nbsp;&nbsp;';
                            }
                            if( v.is_mobile_edit == 1 ){
                            html += '<input type="checkbox" class="is_mobile_edit" checked lay-skin="primary">  是否修改手机号';
                            }else{
                            html += '<input type="checkbox" class="is_mobile_edit" lay-skin="primary">  是否修改手机号';
                            }
                            html += '</td>';

                            //删除json内的元素
                            delete column_data[k] ;
                            return true ;
                        }


                        if( v.is_must == 1 ) {
                            html +='<td style="text-align:center;" ><input type="checkbox" class="is_show" checked disabled lay-skin="primary"></td>';
                            html +='<td style="text-align:center;" ><input type="checkbox" class="is_must" checked lay-skin="primary"></td>';
                        } else if( v.is_show == 1 ) {
                            html +='<td style="text-align:center;" ><input type="checkbox" class="is_show" checked lay-skin="primary"></td>';
                            html +='<td style="text-align:center;" ><input type="checkbox" class="is_must" lay-skin="primary"></td>';
                        } else {
                            html +='<td style="text-align:center;" ><input type="checkbox" class="is_show" lay-skin="primary"></td>';
                            html +='<td style="text-align:center;" ><input type="checkbox" class="is_must" lay-skin="primary"></td>';
                        }

                        if( k == 'birthday') {
                            if( v.is_notEdit == 1 ){

                                html += '<td><input type="checkbox" class="is_notEdit" checked lay-skin="primary"> 禁止重复修改</td>';
                            } else {
                                html += '<td><input type="checkbox" class="is_notEdit"  lay-skin="primary"> 禁止重复修改</td>';
                            }

                        }else if( k == 'mobile'){

                            html += '<td>';
                            if( v.is_proving == 1 ) {
                                html += '<input type="checkbox" class="is_proving" checked lay-skin="primary">  是否开启短信验证&nbsp;&nbsp;&nbsp;&nbsp;';
                            }else {
                                html += '<input type="checkbox" class="is_proving"  lay-skin="primary"> 是否开启短信验证&nbsp;&nbsp;&nbsp;&nbsp;';
                            }
                            if( v.is_mobile_edit == 1 ){
                                html += '<input type="checkbox" class="is_mobile_edit" checked lay-skin="primary">  是否修改手机号';
                            }else{
                                html += '<input type="checkbox" class="is_mobile_edit"  lay-skin="primary"> 是否修改手机号';
                            }
                            html += '</td>';

                        }else if( k == 'marryDay') {
                            if( v.is_marry_notEdit == 1 ){
                                html += '<td><input type="checkbox" class="is_marry_notEdit" checked lay-skin="primary"> 禁止重复修改</td>';
                            } else {
                                html += '<td><input type="checkbox" class="is_marry_notEdit" lay-skin="primary"> 禁止重复修改</td>';
                            }

                        }else if( k == 'referee') {
                            if( v.is_recom_notEdit == 1 ){
                                html += '<td><input type="checkbox" class="is_recom_notEdit" checked lay-skin="primary"> 禁止重复修改</td>';
                            } else {
                                html += '<td><input type="checkbox" class="is_recom_notEdit" lay-skin="primary"> 禁止重复修改</td>';
                            }

                        } else if( k == 'mobile' ) {
                            html += '<td><input type="checkbox" class="is_proving" lay-skin="primary">  是否开启短信验证</td>';

                        } else {
                            html += '<td></td>';
                        }


                        html +='</tr>';

                        //删除json内的元素
                        delete column_data[k] ;

                    }) ;
                }

                //判断json中是否存在其他元素
                if( !$.isEmptyObject( column_data ) ) {

                    $.each(column_data, function (k, v) {

                        html += '<tr class="column layui-form" name="' + k + '">';
                        html += '<td style="text-align:center;">' + v + '</td>';
                        html += '<td style="text-align:center;" ><input type="checkbox" class="is_show" lay-skin="primary"></td>';
                        html += '<td style="text-align:center;" ><input type="checkbox" class="is_must" lay-skin="primary"></td>';

                        if( k == 'birthday') {
                            html += '<td><input type="checkbox" class="is_notEdit" lay-skin="primary"> 禁止重复修改</td>';
                        }else if( k == 'mobile'){
                            html += '<td><input type="checkbox" class="is_proving" lay-skin="primary"> 是否开启短信验证&nbsp;&nbsp;&nbsp;&nbsp;' +
                                '<input type="checkbox" class="is_mobile_edit" lay-skin="primary"> 是否修改手机号</td>';
                        }else if( k == 'marryDay') {
                            html += '<td><input type="checkbox" class="is_marry_notEdit" lay-skin="primary"> 禁止重复修改</td>';
                        }else if( k == 'referee') {
                            html += '<td><input type="checkbox" class="is_recom_notEdit" lay-skin="primary"> 禁止重复修改</td>';
                        } else  if( k == 'mobile') {
                            html += '<td><input type="checkbox" class="is_proving" lay-skin="primary"> 是否开启短信验证</td>';
                        } else {
                            html += '<td></td>';
                        }

                        html += '</tr>';

                    })
                }

                //向表格中插入行
                $('#sortable_tr').append( html ) ;

                //行拖动事件
                $("#sortable_tr").sortable({
                    cursor: "move"
                });

                layui.use(['form'], function(){

                    var form = layui.form();

                    form.on('checkbox', function(data){

                        var obj = data.elem;

                        var is_checked = data.elem.checked;

                        if ( is_checked ) {

                            if ( $(obj).hasClass('is_must')) {
                                $(obj).parents('tr').find('.is_show').attr('disabled',true);
                                $(obj).parents('tr').find('.is_show')[0].checked = data.elem.checked;
                            }

                            if ( $(obj).hasClass('is_proving') ) {

                                $(obj).parents('tr').find('.is_must').attr('disabled',true);
                                $(obj).parents('tr').find('.is_show').attr('disabled',true);
                                $(obj).parents('.layui-form').find('input').each(function(index, item){
                                    item.checked = data.elem.checked;
                                });

                                form.render('checkbox');
                                return false;
                            }

                            if ( $(obj).hasClass('is_show') ) {
                                $(this).attr('checked',true);
                            }

                        } else {

                            if ( $(obj).hasClass('is_must')) {
                                $(obj).parents('tr').find('.is_show').removeAttr('disabled');
                                $(obj).parents('tr').find('.is_must').removeAttr('checked');
                            }

                            if ( $(obj).hasClass('is_proving') ) {
                                $(this).parents('tr').find('.is_must').removeAttr('disabled');
                            }

                            if ( $(obj).hasClass('is_show') ) {
                                $(this).removeAttr('checked');
                            }

                        }

                        form.render('checkbox');

                    });
                });

//            }
        });

        var func = {

            function_id : <?php echo e(isset($function_id) ? $function_id : ''); ?>,

            //保存
            edit:function(){

                var configure = { };
                configure.function_id = $('#function_id').val() ;

                //循环保存
                $('.column').each( function () {

                    var is_must = $(this).find('.is_must').is(':checked') ? 1 : 0 ;
                    var is_show = is_must ? 1 : $(this).find('.is_show').is(':checked') ? 1 : 0 ;
                    var is_mobile_edit = $(this).find('.is_mobile_edit').is(':checked') ? 1 : 0 ;

                    if( $(this).find('.is_notEdit').is(':checked') )  {
                        configure[$(this).attr('name')] = { is_must: is_must , is_show : is_show ,is_notEdit : 1} ;
                    }else if( $(this).find('.is_proving').is(':checked') )  {
                        configure[$(this).attr('name')] = { is_must: is_must , is_show : is_show ,is_proving : 1,is_mobile_edit:is_mobile_edit} ;
                    }else if( $(this).find('.is_marry_notEdit').is(':checked') )  {
                        configure[$(this).attr('name')] = { is_must: is_must , is_show : is_show ,is_marry_notEdit : 1} ;
                    }else if( $(this).find('.is_recom_notEdit').is(':checked') )  {
                        configure[$(this).attr('name')] = { is_must: is_must , is_show : is_show ,is_recom_notEdit : 1} ;
                    }else if( $(this).find('.is_proving').is(':checked') )  {
                        configure[$(this).attr('name')] = { is_must: is_must , is_show : is_show ,is_proving : 1,is_mobile_edit:is_mobile_edit} ;
                    } else {
                        configure[$(this).attr('name')] = { is_must: is_must , is_show : is_show ,is_mobile_edit:is_mobile_edit} ;
                    }
                }) ;

                var index  = layer.load() ;
                E.ajax( {
                    type:'get',
                    url: '/lar/develop/function/store/'+func.function_id,
                    data: configure,
                    dataType:'json',

                    // 返回值判断
                    success: function ( obj ){

                        layer.close( index) ;

                        if ( obj.code == 200 ) {
                            layer.alert( obj.message , { icon: 1,time : 1500 } ) ;
                        } else {
                            layer.alert( obj.message , { icon: 2 } ) ;
                        }
                    }
                } ) ;

            }

        } ;


    </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('develop.layoutEdit', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>